package com.ss.android.pay;

import android.text.TextUtils;
import android.util.Base64;
import com.bytedance.common.utility.Logger;
import java.lang.ref.WeakReference;
import java.security.KeyFactory;
import java.security.PublicKey;
import java.security.Signature;
import java.security.spec.X509EncodedKeySpec;

abstract class e implements l {
    private WeakReference a;
    protected h c;

    e(h arg2, j arg3) {

        this.c = arg2;
        this.a = new WeakReference(arg3);
    }

    private static boolean a(String arg3, String arg4, String arg5) {
        boolean v0 = false;
        try {
            PublicKey v1_1 = KeyFactory.getInstance("RSA").generatePublic(new X509EncodedKeySpec(Base64.decode(arg3.getBytes("utf-8"), 0)));
            Signature v2 = Signature.getInstance("SHA1withRSA");
            v2.initVerify(v1_1);
            v2.update(arg5.getBytes());
            v0 = v2.verify(Base64.decode(arg4, 0));
        }
        catch(Throwable v1) {
            v1.printStackTrace();
        }

        return v0;
    }

    protected abstract void a() throws PayException;

    public final void a(String arg3) {
        if(this.a != null && this.a.get() != null) {
            this.a(arg3, (j) this.a.get());
        }
        else if(Logger.debug()) {
            Logger.w("PaySession", "callback is null or destroyed");
        }

        k.a().a(((l)this));
    }

    protected abstract void a(String arg1, j arg2);

    public final void b() throws PayException {
        try {
            boolean v0_1 = this.c == null || (TextUtils.isEmpty(this.c.a)) || (TextUtils.isEmpty(this.c.k)) ? false : e.a("MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDOZZ7iAkS3oN970+yDONe5TPhPrLHoNOZOjJjackEtgbptdy4PYGBGdeAUAz75TO7YUGESCM+JbyOz1YzkMfKl2HwYdoePEe8qzfk5CPq6VAhYJjDFA/M+BAZ6gppWTjKnwMcHVK4l2qiepKmsw6bwf/kkLTV9l13r6Iq5U+vrmwIDAQAB", this.c.i, this.c.k);
            if(!v0_1) {
                throw new PayException(com.ss.android.article.browser.R.string.jq);
            }

            this.a();
            return;
        }
        catch(PayException v0) {
            k.a().a(((l)this));
            throw v0;
        }
    }
}

